<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background-color: blue;
        }

        .box {
            width: 500px;
            margin: 50px auto;
        }

        img {
            transition: transform 1s;
        }
    </style>
</head>

<body>
    <button id="breakUpBtn">打散</button>
    <button id="combineBtn">合并</button>
    <div class="box">
        <!-- img[src="./images/shield_1_0$.png"]*9 -->
        <img src="./images/shield_1_01.png" alt="">
        <img src="./images/shield_1_02.png" alt="">
        <img src="./images/shield_1_03.png" alt="">
        <img src="./images/shield_1_04.png" alt="">
        <img src="./images/shield_1_05.png" alt="">
        <img src="./images/shield_1_06.png" alt="">
        <img src="./images/shield_1_07.png" alt="">
        <img src="./images/shield_1_08.png" alt="">
        <img src="./images/shield_1_09.png" alt="">
    </div>

    <script>
        var breakUpBtn = document.querySelector("#breakUpBtn")

        var combineBtn = document.querySelector("#combineBtn")
        // 获取所以的盾牌图片
        var imgs = document.querySelectorAll('img');

        // 打散
        breakUpBtn.onclick = function () {
            /* 
            1 小图片 位置和角度都改变 
                位置 translate(随机)  旋转 rotate (随机 ) 
            2  对所有图片for循环
                在循环里面
                  计算 x y  
                  计算角度 
                  动态的设置到dom对象就可以了 
             */
            console.log("adas");
            

            for (var i = 0; i < imgs.length; i++) {
                var x = Math.round(Math.random() * 800) - 400;
                var y = Math.round(Math.random() * 600) - 300;
                var deg = Math.random() * 360;
                var im = imgs[i];
                im.style.transform = "translate(" + x + "px," + y + "px) rotate("+deg+"deg)"
            }


        }

        // 合并
        combineBtn.onclick = function () {
            for (var i = 0; i < imgs.length; i++) {
                var im = imgs[i];
                im.style.transform = "none"
            }
        }
    </script>
</body>

</html>